package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.FpermissionDAO;
import entity.Fpermission;

@WebServlet("/permission")
public class  AddPermissionServlet extends HttpServlet {
	private FpermissionDAO permissiondao = new FpermissionDAO();
	private String action;
	

	public AddPermissionServlet() {
		super();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		this.action=request.getParameter("userno");
		Permission_add(request);
		request.getRequestDispatcher("/UserList.jsp").forward(request, response);
	}

	private void Permission_add(HttpServletRequest request) {
		try {
			Fpermission fp=new Fpermission();
			int draftkey=0,passkey=0,executionkey=0,moneykey=0,powerkey=0,companykey=0;
			fp.setUserno(this.action);
			//String userno="1";
			//fp.setUserno(userno);
			String[] uids =request.getParameterValues("x");
			for(int i=0;i<request.getParameterValues("x").length;i++)
			{
				char [] stringArr = uids[i].toCharArray();
				if(uids[i].equals("草拟"))draftkey=1;else ;
				if(uids[i].equals("审批"))passkey=1;else ;
				if(uids[i].equals("执行"))executionkey=1;else ;
				if(uids[i].equals("收/付情况"))moneykey=1;else ;
				if(uids[i].equals("客户管理"))companykey=1;else ;
				if(uids[i].equals("功能权限管理"))powerkey=1;else ;
			}
			fp.setDraftkey(draftkey);
		    fp.setPasskey(passkey);
		    fp.setExecutionkey(executionkey);
			fp.setMoneykey(moneykey);
			fp.setPowerkey(powerkey);
			fp.setCompanykey(companykey);
			this.permissiondao.permission_edit(fp);
	        
		 } catch (Exception ex) {
			 
	         request.setAttribute("errormsg", ex.getMessage());
	         
	     }
		
	}
}
